package com.slz3.business.module.wmsManagement.wmsPurchaseOrderSelf.steward;

import com.slz3.business.frame.response.RR;
import com.slz3.business.frame.response.ResInfo;
import com.slz3.business.frame.util.BeanValidators;
import com.slz3.business.module.wmsManagement.wmsPurchaseOrderSelf.domain.WmsPurchaseOrderSelf;
import com.slz3.business.module.wmsManagement.wmsPurchaseOrderSelf.domain.WmsPurchaseOrderSelfCondition;
import com.slz3.business.module.wmsManagement.wmsPurchaseOrderSelf.req.AddForm;
import com.slz3.business.module.wmsManagement.wmsPurchaseOrderSelf.req.UpdateForm;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

public class WmsPurchaseOrderSelfResController extends WmsPurchaseOrderSelfResAtomic {

    public Mono<ServerResponse> add(ServerRequest req, AddForm form) {
        // 参数校验
        BeanValidators.ValidatorResult result = BeanValidators.validate(form);

        if (result.hasError()){
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(result.getFieldErrors().toString()).build());
        }
        return super.add_$WmsPurchaseOrderSelfUpdateLock(req, form);
    }

    public Mono<ServerResponse> delete(ServerRequest req, WmsPurchaseOrderSelfCondition wmsPurchaseOrderSelfCondition) {
        if (WmsPurchaseOrderSelfResUnsafeValid.delete(req, wmsPurchaseOrderSelfCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.delete_$WmsPurchaseOrderSelfUpdateLock(req, wmsPurchaseOrderSelfCondition);
        }
    }

    public Mono<ServerResponse> modify(ServerRequest req, UpdateForm form) {
        // 参数校验
        BeanValidators.ValidatorResult result = BeanValidators.validate(form);
        if(form.getFormLines() == null){
            return RR.error(req, ResInfo.builder().theme("商品信息不存在！").description(result.getFieldErrors().toString()).build());
        }
        if (result.hasError()){
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(result.getFieldErrors().toString()).build());
        }
        return super.modify_$WmsPurchaseOrderSelfUpdateLock(req, form);

    }

    public Mono<ServerResponse> list(ServerRequest req) {
        if (WmsPurchaseOrderSelfResUnsafeValid.list(req)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.list(req);
        }
    }

    public Mono<ServerResponse> info(ServerRequest req) {
//        return wmsPurchaseOrderSelfResAtomic.info_$WmsPurchaseOrderSelfUpdateLock(req);
        if (WmsPurchaseOrderSelfResUnsafeValid.info(req)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.info_$WmsPurchaseOrderSelfUpdateLock(req);
        }
    }

    public Mono<ServerResponse> choice(ServerRequest req) {
        if (WmsPurchaseOrderSelfResUnsafeValid.choice(req)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.choice(req);
        }
    }

    public Mono<ServerResponse> auditSubmit(ServerRequest req, WmsPurchaseOrderSelfCondition wmsPurchaseOrderSelfCondition) {
        //
        if (WmsPurchaseOrderSelfResUnsafeValid.auditSubmit(req, wmsPurchaseOrderSelfCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.auditSubmit_$WmsPurchaseOrderSelfUpdateLock(req, wmsPurchaseOrderSelfCondition);
        }
    }

    public Mono<ServerResponse> audit(ServerRequest req, WmsPurchaseOrderSelfCondition wmsPurchaseOrderSelfCondition) {
        if (WmsPurchaseOrderSelfResUnsafeValid.audit(req, wmsPurchaseOrderSelfCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.audit_$WmsPurchaseOrderSelfUpdateLock(req, wmsPurchaseOrderSelfCondition);
        }
    }

    public Mono<ServerResponse> auditReject(ServerRequest req, WmsPurchaseOrderSelfCondition wmsPurchaseOrderSelfCondition) {
        if (WmsPurchaseOrderSelfResUnsafeValid.auditReject(req, wmsPurchaseOrderSelfCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.auditReject_$WmsPurchaseOrderSelfUpdateLock(req, wmsPurchaseOrderSelfCondition);
        }
    }

    public Mono<ServerResponse> usingEnable(ServerRequest req, WmsPurchaseOrderSelfCondition wmsPurchaseOrderSelfCondition) {
        if (WmsPurchaseOrderSelfResUnsafeValid.usingEnable(req, wmsPurchaseOrderSelfCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.usingEnable_$WmsPurchaseOrderSelfUpdateLock(req, wmsPurchaseOrderSelfCondition);
        }
    }

    public Mono<ServerResponse> usingDisable(ServerRequest req, WmsPurchaseOrderSelfCondition wmsPurchaseOrderSelfCondition) {
        if (WmsPurchaseOrderSelfResUnsafeValid.usingDisable(req, wmsPurchaseOrderSelfCondition)) {
            return RR.error(req, ResInfo.builder().theme(RR.UN_SAFE_VALID).description(RR.ILLEGAL_PARAM).build());
        } else {
            return super.usingDisable_$WmsPurchaseOrderSelfUpdateLock(req, wmsPurchaseOrderSelfCondition);
        }
    }

}
